package com.clz.hyperit.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.clz.hyperit.dao.AnswerDao;
import com.clz.hyperit.entity.Answer;
import com.clz.hyperit.entity.Article;
import com.clz.hyperit.vo.PageInfo;
@Repository("answerDao")
public class AnswerDaoImpl extends BaseDaoImpl<Answer> implements AnswerDao {

	public List<Answer> findByQustion_id(PageInfo pageInfo, Integer question_id) {
		String hql = "from Answer where question_id = :question_id  order by createtime desc";
		@SuppressWarnings("unchecked")
		List<Answer> list = getCurrentSession()
				.createQuery(hql)
				.setInteger("question_id", question_id)
				.setFirstResult(
						(pageInfo.getIndexPageNum() - 1) * pageInfo.getSize())
				.setMaxResults(pageInfo.getSize()).list();
		// 获得表中总的条目数目
		String hql2 = "select count(*) from Answer where question_id = :question_id ";
		Object uniqueResult = getCurrentSession().createQuery(hql2)
				.setInteger("question_id", question_id)
				.uniqueResult();
		Long intValue = (new Integer(uniqueResult.toString())).longValue();
		pageInfo.setTotalCount(intValue);
		return list;
	}

	

}
